package com.java.architect.operator.impl;

import com.java.architect.mapper.ItemMapper;
import com.java.architect.entity.InventoryId;
import com.java.architect.entity.Item;
import com.java.architect.manager.aop.Inventory;
import com.java.architect.operator.InventoryOperator;
import com.java.architect.utils.InvLimitTypeEnum;
import com.java.architect.utils.OperatorResult;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Java架构师之旅
 * @date 2022年05月28日 15:05
 */
@Component
@Inventory("item-manager")
public class ItemManagerOperator implements InventoryOperator {
    @Resource
    ItemMapper itemMapper;
    @Override
    public long getTotal(final InventoryId id) {
        final Item item = this.itemMapper.selectById(id.getId());
        final Integer invLimitType = item.getInvLimitType();
        if(invLimitType.equals(InvLimitTypeEnum.NO_LIMIT.getValue())){
            return Long.MAX_VALUE;
        }
        return item.getInvTotal().longValue();
    }

    @Override
    public long getUsed(final InventoryId id) {
        return 0;
    }

    @Override
    public OperatorResult deduct(final InventoryId id, final long cnt) {
        return null;
    }

    @Override
    public OperatorResult release(final InventoryId id, final long cnt) {
        return null;
    }

    @Override
    public boolean flushUsed(final InventoryId id, final long cnt) {
        return false;
    }
}
